import { Pipe, PipeTransform } from '@angular/core';

/**
 * 订单状态
 */
export const orderStateArrs: any = [
  { id: 11, label: '待上门揽件', color: '#666666' },
  { id: 13, label: '物流运输中', color: '#666666' },
  { id: 14, label: '到货待验机', color: '#666666' },
  { id: 15, label: '待确认交易', color: '#FF9933' },
  { id: 16, label: '待打款', color: '#FF9933' },
  { id: 18, label: '打款失败', color: '#FF0000' },
  { id: 19, label: '打款完成', color: '#008000' },
  { id: 20, label: '揽件前取消', color: '#666666' },
  { id: 21, label: '验机中', color: '#666666' },
  { id: 22, label: '待退回', color: '#FF9900' },
  { id: 23, label: '退回途中', color: '#666666' },
  { id: 24, label: '已退回', color: '#666666' },
  { id: 25, label: '异常关闭', color: '#666666' },
  // { id: 91, label: '取消交易', color: '#FF9900' },
];
@Pipe({
  name: 'orderState'
})
export class OrderStatePipe implements PipeTransform {

  transform(value: any, type: string) {
    if (value) {
      let tempObj = orderStateArrs.find((item: any) => {
        return item.id == value;
      })

      switch (type) {
        case 'text':
          return tempObj ? tempObj.label : '-';
        case 'color':
          return tempObj ? tempObj.color : '#333333';
      }
    } else {
      return '-';
    }
  }

}

/**
 * 验机结果
 */
export const machineResultArrs: any = [
  { id: 11, label: '验机结果与评估一致', color: '#666666' },
  { id: 12, label: '机况存在差异', color: '#666666' },
  { id: 13, label: '机型不一致', color: '#666666' },
  { id: 14, label: '一单多机', color: '#666666' },
  { id: 15, label: '不支持回收', color: '#666666' }
];
@Pipe({
  name: 'machineResult'
})
export class MachineResultPipe implements PipeTransform {

  transform(value: any) {
    if (value) {
      let tempObj = machineResultArrs.find((item: any) => {
        return item.id == value;
      })
      return tempObj ? tempObj.label : '-';
    } else {
      return '-';
    }
  }

}

/**
 * 验机状态 1-验机中断 2-待继续验机 3-验机完成 4-部分验机 5-无法验机
 */
export const machineInspectionArrs: any = [
  { id: 1, label: '验机中断', color: '#666666' },
  { id: 2, label: '待继续验机', color: '#666666' },
  { id: 3, label: '验机完成', color: '#666666' },
  { id: 4, label: '部分验机', color: '#666666' },
  { id: 5, label: '无法验机', color: '#666666' }
];
@Pipe({
  name: 'machineInspectionStatus'
})
export class MachineInspectionStatusPipe implements PipeTransform {

  transform(value: any) {
    if (value) {
      let valArr = String(value).split(',');
      let tmpMachs = machineInspectionArrs.map((tag: any) => tag.id);
      let tmpArr: any = [];
      valArr.forEach((val: any) => {
        if (tmpMachs.includes(Number(val))) {
          let obj = machineInspectionArrs.find((ele: any) => ele.id == val);
          tmpArr.push(obj.label);
        }
      })

      return tmpArr.length ? (tmpArr.length > 3 ? ((tmpArr.slice(0, 3).join('、')) + '...') : tmpArr.join(','))  : '-';
    } else {
      return '-';
    }
  }

}

/**
 * ----------------------------------------------------------------
 * 下单抽奖状态
 * 状态 0.未开始 1.进行中 2.已删除 3.已结束 4.禁用
 * ----------------------------------------------------------------
 */
export const loveLuckDrawStatusArrs: any = [
  { value: 0, label: '未开始', color: '#909399' },
  { value: 1, label: '进行中', color: '#67C23A' },
  { value: 3, label: '已结束', color: '#F56C6C' },
  { value: 4, label: '禁用', color: '#F56C6C' }
];
@Pipe({
  name: 'loveLuckDrawStatus'
})
export class LoveLuckDrawStatusPipe implements PipeTransform {
  transform(value: any, type: string) {
    let tempObjs: any = loveLuckDrawStatusArrs.find((item: any) => item.value === value);

    if (type === 'color') {
      return tempObjs?.color || '';
    } else {
      return tempObjs?.label || '-';
    }
  }
}

/**
 * ----------------------------------------------------------------
 * 下单抽奖 奖品类型
 * 奖品类型 1-回收成交加价、2-配件优惠券 、3-二手优惠券、4-谢谢惠顾
 * ----------------------------------------------------------------
 */
export const lovePrizeTypeArrs: any = [
  { value: 1, label: '回收成交加价', color: '#909399' },
  { value: 2, label: '配件优惠券', color: '#67C23A' },
  { value: 3, label: '二手优惠券', color: '#F56C6C' },
  { value: 4, label: '谢谢惠顾', color: '#F56C6C' }
];
@Pipe({
  name: 'lovePrizeType'
})
export class LovePrizeTypePipe implements PipeTransform {
  transform(value: any, type: string) {
    let tempObjs: any = lovePrizeTypeArrs.find((item: any) => item.value === value);

    if (type === 'color') {
      return tempObjs?.color || '';
    } else {
      return tempObjs?.label || '-';
    }
  }
}

/**
 * ----------------------------------------------------------------
 * 回收送爱豆管理 活动状态
 * 活动状态 1-未开始、2-进行中、3-已结束、4-已终止、5-草稿
 * ----------------------------------------------------------------
 */
export const loveRecycActstatusArrs: any = [
  { value: 1, label: '未开始', color: '#E6A23C' },
  { value: 2, label: '进行中', color: '#67C23A' },
  { value: 3, label: '已结束', color: '#F56C6C' },
  { value: 4, label: '已终止', color: '#F56C6C' },
  { value: 5, label: '草稿', color: '#909399' }
];
@Pipe({
  name: 'loveRecoveryActstatus'
})
export class LoveRecoveryActstatusPipe implements PipeTransform {
  transform(value: any, type: string) {
    let tempObjs: any = loveRecycActstatusArrs.find((item: any) => item.value === value);

    if (type === 'color') {
      return tempObjs?.color || '';
    } else {
      return tempObjs?.label || '-';
    }
  }
}

/**
 * ----------------------------------------------------------------
 * 回收送爱豆记录 赠送状态
 * 赠送状态 1.待到账 2.已到账 3.已冻结 4.余额不足 5.已失效
 * ----------------------------------------------------------------
 */
export const loveRecycGivestatusArrs: any = [
  { value: 1, label: '待到账', color: '#909399' },
  { value: 2, label: '已到账', color: '#67C23A' },
  { value: 3, label: '已冻结', color: '#409EFF' },
  { value: 4, label: '余额不足', color: '#E6A23C' },
  { value: 5, label: '已失效', color: '#F56C6C' }
];
@Pipe({
  name: 'loveRecoveryGivestatus'
})
export class LoveRecoveryGivestatusPipe implements PipeTransform {
  transform(value: any, type: string) {
    let tempObjs: any = loveRecycGivestatusArrs.find((item: any) => item.value === value);

    if (type === 'color') {
      return tempObjs?.color || '';
    } else {
      return tempObjs?.label || '-';
    }
  }
}

